package com.example.login.service;
import com.example.login.entity.User;
import com.example.login.entity.UserCourse;
import com.example.login.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public boolean deleteUser(String userName) {
        User user = userMapper.findByUsername(userName);
        if (user != null) {
            userMapper.delete(user);
            return true;
        } else {
            return false;
        }

    }
    public boolean editUser(String userName, String name, String major, String className, String password) {
        User login = userMapper.findByUsername(userName);
        if (login == null) {
            return false;
        }
        login.setName(name);
        login.setMajor(major);
        login.setClass_name(className);
        login.setPassword(password);
        int result = userMapper.updateByPrimaryKeySelective(login);
        return result > 0;
    }

    public List<User> getUserInfo(String name, String major, String class_name, String studentNum) {
        List<User> userInfoList = userMapper.getUserInfo(name, major, class_name, studentNum);
        return userInfoList;

    }


    public List<UserCourse> getStudentScore(String userName, String semester) {
        // 根据userName或studentNum和semester查询UserCourse表，返回查询结果
        List<UserCourse> userCourseList = userMapper.getStudentScore(userName, semester);
        return userCourseList;
    }

}
